<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.0&ak=QwOix7gzb8PX2SQIzSYZXNqDukVO8AdO"></script>
<title>自定义图层</title>
<style>
body, html {
    overflow: hidden;
    height: 100%;
    margin: 0;
    padding: 0;
}
#map_container {
    width: auto;
    height: 580px;
}
</style>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
</head>
<body style="margin:0">
<div id="map_container"></div>
</body>
</html>
<script>
var map = new BMap.Map('map_container');
map.centerAndZoom(new BMap.Point(116.123695,24.338252), 18);
map.enableKeyboard();
map.enableScrollWheelZoom();

var points = [
    {lng: 116.124512, lat: 24.338421, name: "共享单车"},
    {lng: 116.124665, lat: 24.338314, name: "共享单车"},
    {lng: 116.12241, lat: 24.340058, name: "共享单车"},
    {lng: 116.124566, lat: 24.33768, name: "共享单车"},
    {lng: 116.125433, lat: 24.339729, name: "共享单车"},
    {lng: 116.128322, lat: 24.339332, name: "共享单车"},
    {lng: 116.125728, lat: 24.33768, name: "共享单车"},
    {lng: 116.126338, lat: 24.33768, name: "共享单车"},
    {lng: 116.123933, lat: 24.338174, name: "车库A1"},
    {lng: 116.122639, lat: 24.339449, name: "车库A2"},
    {lng: 116.123776, lat: 24.339416, name: "车库B1"},
    {lng: 116.12542, lat: 24.338746, name: "车库B2"},
    {lng: 116.122343, lat: 24.337507, name: "车库C1"},
    {lng: 116.12515, lat: 24.337544, name: "车库C2"}
];

points.forEach(function(pointInfo) {
    var point = new BMap.Point(pointInfo.lng, pointInfo.lat);
    var marker = new BMap.Marker(point);
    map.addOverlay(marker);

    var label = new BMap.Label(pointInfo.name, { offset: new BMap.Size(20, -10) });
    if (pointInfo.name.includes("共享单车")) {
        label.setStyle({
            color: "red",
            fontSize: "12px",
            height: "20px",
            lineHeight: "20px",
            fontFamily: "微软雅黑"
        });
    } else {
        label.setStyle({
            color: "green",
            fontSize: "12px",
            height: "20px",
            lineHeight: "20px",
            fontFamily: "微软雅黑"
        });
    }
    marker.setLabel(label);
});
</script>